jQ(function(){
	jQ("div.my_clips_menu a.clipmanage").addClass("clipmanageonit");
	jQ("#left_clip_list").empty();
	jQ("input.hminput").val(0);
	
	
	jQ("#remindchooseipt").val("").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		beforeShow: function(i,e){  
			var z = jQuery(i).closest(".ui-dialog").css("z-index") + 4;  
			e.dpDiv.css('z-index', z);  
		},
		onSelect: function(dateText, inst) {
			jQ("#mainpart_list_content").data("currentpage",0);
			loadRemindMainpartRecords(dateText);
		}
	});
	analyzeUrl();
	
	initLeftCalendar();
	loadTodayEvents();
	loadRemindMainpartRecords();
	jQ("#viewopt").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		closeOnEscape:false,
		draggable:false,
		height:200,
		buttons: {
			
			"确定": function() {
				var opt=jQ("#viewopt");
				var triggerfun=opt.data("function");
				opt.trigger(triggerfun);
				opt.removeData("function");
				jQ("#viewopt_p").hide();
				jQ("#viewopt_img").show();
				activeBtnOnDialog("viewopt",false);
				//jQ(this).dialog('close');
			},
			"取消": function() {
				var viewopt=jQ("#viewopt");
				var triggerfun=jQ("#viewopt").data("function");
				viewopt.unbind(triggerfun);
				viewopt.find("input.eventid").val("");
				viewopt.removeData("function");
				jQ(this).dialog('close');
			}
		},
		close: function() {
			jQ("#viewopt_p").show();
			jQ("#viewopt_img").hide();
			activeBtnOnDialog("viewopt",true);
		},
		open:function(){
			jQ("#viewopt_p").show();
			jQ("#viewopt_img").hide();
		}
	});
	/*
	jQ("div.samepage a").click(function(){
		if(jQ(this).hasClass("onit")){
			return;
		}else{
			jQ("div.samepage a.onit").removeClass("onit");
			jQ(this).addClass("onit");
			jQ("#mainpart_list_content").data("currentpage",0);
			loadRemindMainpartRecords();
		}
	});*/
	jQ("div.upscreen").click(function(){
		if(jQ(this).hasClass("onit")){
			jQ(this).removeClass("onit");
			jQ(this).parent("div.et_screen").find("div.src_all").hide();
		}else{
			jQ(this).addClass("onit");
			jQ(this).parent("div.et_screen").find("div.src_all").show();
		}
	});
	jQ("div.dwscreen").click(function(){
		if(jQ(this).hasClass("onit")){
			jQ(this).removeClass("onit");
			jQ(this).parent("div.et_screen").find("div.src_all").hide();
		}else{
			jQ(this).addClass("onit");
			jQ(this).parent("div.et_screen").find("div.src_all").show();
		}
	});	
	
	jQ("span.upgoto").click(function(){
		if(jQ(this).hasClass("onit")){
			jQ(this).removeClass("onit");
			jQ(this).parent("div.page").find("div.home_end").hide();
		}else{
			jQ(this).addClass("onit");
			jQ(this).parent("div.page").find("div.home_end").show();
		}
	});
	
	jQ("span.dwgoto").click(function(){
		if(jQ(this).hasClass("onit")){
			jQ(this).removeClass("onit");
			jQ(this).parent("div.page").find("div.home_end").hide();
		}else{
			jQ(this).addClass("onit");
			jQ(this).parent("div.page").find("div.home_end").show();
		}
	});
	jQ("a.next").click(function(){
		var pagecount=eval(jQ("#mainpart_list_content").data("pagecount"));
		var currentpage=eval(jQ("#mainpart_list_content").data("currentpage"));
		if(currentpage+1>=pagecount){
			return;
		}else{
			currentpage++;
			jQ("#mainpart_list_content").data("currentpage",currentpage);
			loadRemindMainpartRecords();
		}
	});
	
	jQ("a.prev").click(function(){
		var pagecount=eval(jQ("#mainpart_list_content").data("pagecount"));
		var currentpage=eval(jQ("#mainpart_list_content").data("currentpage"));
		if(currentpage==0){
			return;
		}else{
			currentpage--;
			jQ("#mainpart_list_content").data("currentpage",currentpage);
			loadRemindMainpartRecords();
		}
	});
	
	jQ("span.firstpage").click(function(){
		var currentpage=eval(jQ("#mainpart_list_content").data("currentpage"));
		if(currentpage==0){
			jQ("div.home_end").hide();
			return;
		}
		currentpage=0;
		jQ("#mainpart_list_content").data("currentpage",currentpage);
		loadRemindMainpartRecords();
		jQ("div.home_end").hide();
	});
	jQ("span.lastpage").click(function(){
		var pagecount=eval(jQ("#mainpart_list_content").data("pagecount"));
		var currentpage=eval(jQ("#mainpart_list_content").data("currentpage"));
		if(currentpage==pagecount-1){
			jQ("div.home_end").hide();
			return;
		}
		currentpage=pagecount-1;
		jQ("#mainpart_list_content").data("currentpage",currentpage);
		loadRemindMainpartRecords();
		jQ("div.home_end").hide();
	});
});

function analyzeUrl(){
	var currentpage=eval(getParameter("currentpage"));
	if(isNaN(currentpage)||currentpage==null){
		jQ("#mainpart_list_content").data("currentpage",0);
	}else{
		jQ("#mainpart_list_content").data("currentpage",currentpage);
	}
	var year=eval(getParameter("year"));
	var month=eval(getParameter("month"));
	var day=eval(getParameter("date"));
	if(!isNaN(year)&&year!=null
			&&!isNaN(month)&&month!=null
			&&!isNaN(day)&&day!=null){
		var date=new Date();
		date.setFullYear(year,month,day);
		date.setMinutes(0,0,0);
		
		jQ("#remindchooseipt").datepicker( "setDate",date );
	}
}

function chooseall(){
	jQ("#remindchooseipt").val("");
	loadRemindMainpartRecords();
}

function choosetoday(){
	var systime=jQ("#var_systemtime").val();
	var temp=new Date();
	temp.setTime(systime);
	jQ("#remindchooseipt").datepicker( "setDate" ,temp);
	loadRemindMainpartRecords();
}
var PAGESIZE=15;
function loadRemindMainpartRecords(dateText){
	var temp;
	var year=0;
	var month=0;
	var date=0;
	if(dateText!=null&&dateText.length>0){
		var selectedtime=Date.parse(dateText);
		temp=new Date();
		temp.setTime(selectedtime);
		year=temp.getYear()>1500?temp.getYear():temp.getYear()+1900;
		month=temp.getMonth();
		date=temp.getDate();
	}else{
		if(jQ("#remindchooseipt").val().length>0){
			temp=jQ("#remindchooseipt").datepicker( "getDate" );
			year=temp.getYear()>1500?temp.getYear():temp.getYear()+1900;
			month=temp.getMonth();
			date=temp.getDate();
		}
	}
	var currentpage=eval(jQ("#mainpart_list_content").data("currentpage"));
	jQ.ajax({
		type:"POST",
		url: "manageClipAjax!loadRemindMainpartRecords.action",
		data:{
			currentpage:currentpage,
			year:year,
			month:month,
			date:date
		},
		success:function(data){
			var clocktotalcount=eval(jQ(data).find("totalcount").text());
			var remindtotalcount=eval(jQ(data).find("remindtotalcount").text());
			jQ("#clipevent_clocknum").empty().append("("+remindtotalcount+")");
			var cachetotalcount=eval(jQ(data).find("cachetotalcount").text());
			jQ("#clipevent_cachenum").empty().append("("+cachetotalcount+")");
			var recycletotalcount=eval(jQ(data).find("recycletotalcount").text());
			jQ("#clipevent_recyclenum").empty().append("("+recycletotalcount+")");
			
			currentpage=eval(jQ(data).find("currentpage").text());
			jQ("#mainpart_list_content").data("currentpage",currentpage);
			var totalcount=eval(jQ(data).find("totalcount").text());
			var pagecount=eval(jQ(data).find("pagecount").text());
			jQ("#mainpart_list_content").data("pagecount",pagecount);
			var currentrecordcount=eval(jQ(data).find("currentrecordcount").text());
			if(totalcount>1)
				jQ("b.clippage_currentrecordcount").empty().append(currentpage*PAGESIZE+1+"-"+(currentpage*PAGESIZE+currentrecordcount));
			else
				jQ("b.clippage_currentrecordcount").empty().append(totalcount);
			jQ("b.clippage_totalcount").empty().append(totalcount);
			var html="";
			jQ(data).find("EventForView").each(function(){
				var eventid=jQ(this).attr("id");
				var title=jQ(this).find("title").text();
				var eventtype=jQ(this).find("eventtype").text();
				var starttime=eval(jQ(this).find("starttime").text());
				var endtime=eval(jQ(this).find("endtime").text());
				var iswholeday=eval(jQ(this).find("iswholeday").text());
				var address=jQ(this).find("address").text();
				var clocktime=eval(jQ(this).find("clocktime").text());
				var clockstr=eval(jQ(this).find("alertstr").text());
				var deadlinetime=eval(jQ(this).find("deadlinetime").text());
				var isexpire=eval(jQ(this).find("isexpire").text());
				var isvip=eval(jQ(this).find("isvip").text());
				var processstatus=eval(jQ(this).find("processstatus").text());
				var clipstatus=eval(jQ(this).find("clipstatus").text());
				var reliedclip=eval(jQ(this).find("reliedclip").text());
				var publishname=jQ(this).find("publishname").text();
				var forwardname=jQ(this).find("forwardname").text();
				var fuid=eval(jQ(this).find("fuid").text());
				var cliptype=eval(jQ(this).find("cliptype").text());
				var isinvited=eval(jQ(this).find("isinvited").text());	
				if(reliedclip==0){
					html+="<tr class='mine' id='clipevent-"+eventid+"' title='我添加的档期'>";
				}else{
					if(clipstatus==0){
						html+="<tr class='unjoin' id='clipevent-"+eventid+"' title='收到的邀请'>";
					}else if(clipstatus==1){
						html+="<tr class='join' id='clipevent-"+eventid+"' title='我参加的档期'>";
					}
				}
				
				html+="<input type='hidden' class='eventid' value='"+eventid+"'>";
				html+="<input type='hidden' class='clocktime' value='"+clocktime+"'>";
				html+="<input type='hidden' class='isvip' value='"+isvip+"'>";
				html+="<td width='20' class='noclick'><div class='eb_item noclick'><input type='hidden' value='"+eventid+"'><input type='checkbox' class='cbx per'/></div></td>";
				if(isvip)
					html+="<td width='20' class='isvip noclick'><div class='eb_item isvip-"+eventid+" noclick'><span class='c_import isvip noclick' title='重要档期'></span></div></td>";
				else
					html+="<td width='20' class='isvip noclick'><div class='eb_item isvip-"+eventid+" noclick'><span class='import isvip noclick' title='不重要档期'></span></div></td>";
				if(fuid>0){
					html+="<td width='125' class='noclick'><div class='eb_item noclick'><span class='name noclick'  title='推送者'>"+forwardname+"</span></div></td>";
				}else
					html+="<td width='125' class='noclick'><div class='eb_item noclick'><span class='name noclick'  title='推送者'>"+publishname+"</span></div></td>";
				html+="<td width='350'><div class='eb_item eventtype-"+eventtype+"'><span class='title "+eventtype+"' title='档期内容'>"+htmlData(title)+"</span></div></td>";
				html+="<td width='60'>";
				if(cliptype==3){
					html+="<span class='share' title='分享档期'></span>";
				}
				if(isinvited)
					html+="<span class='invite' title='多人参与'></span>";
				html+="</td>";
				html+="<td width='145'><div class='eb_item'>";
				if(processstatus==0){
					html+="<b class='clip_ing' title='进行中'></b>";
				}else if(processstatus==1){
					html+="<b class=\"clip_over\" title='已结束'></b>";
				}else if(processstatus==2){
					html+="<b class=\"clip_stop\" title='已停止'></b>";
				}
				html+="<span class='time' title='活动时间'>";
				if(iswholeday)
					html+="<span style='width:auto;'>开始于</span><b class='first'>"+formateDetailTime(starttime)+"</b>";
				else
					html+="<b class='first'>"+formateDetailTime(starttime)+"</b><b class='second'>"+formateDetailTime(endtime)+"</b>";
				html+="</span></div></td>";
				html+="<td width='110'><div class='eb_item'><span class='end_time' title='回复截止时间'>";
				if(deadlinetime<=0){
					html+="<i>暂无</i>";
				}else{
					html+="<span>回复截止：</span>";
					if(isexpire)
						html+="<span class='expire'>已过期</span>";
					html+="<span class='end_time'>";
					html+=formateDetailTime(deadlinetime);
				}
				html+="</span>";
				html+="<td width='110'  title='提醒于 "+formatCreatetimeTitle(clockstr)+"'><div class='eb_item'><span class='getime'>"+formatCreatetime(clockstr)+"</span></div></td>";
				html+="</tr>";
			});
			jQ("#mainpart_list_content").empty().append(html);
			jQ("input.per").click(function(event){
				event.stopPropagation();
			});
			jQ("#mainpart_list_content tr").click(function(event){
				var tar=event.target;
				if(jQ(tar).hasClass("noclick"))
					return;
				var currentpage=eval(jQ("#mainpart_list_content").data("currentpage"));
				
				var eventid=eval(jQ(this).find("input.eventid").val());
				window.location.href=jQ("#ctxVal").val()+"/myclip/remind_detail.html?eventid="+eventid+"&currentpage="+currentpage;
			});
		}
	});
}

function initLeftCalendar(){
	jQ("#datepicker").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		onSelect: function(dateText, inst) {
			var selectedDate=Date.parse(dateText);
			if(jQ("div.ms_box[dayattr='"+selectedDate+"']").length>0){
				//已经显示的日期事件去除
				jQ("div.ms_box[dayattr='"+selectedDate+"']").fadeOut("normal",function(){
					   jQ(this).remove();
				 });
				
			}else{
				loadDefinedDateEvents(selectedDate);
				//未显示的日期事件显示
			}
		}
	});//获取日历
//	jQ("#datepicker").children("div").width("254px");//设置日历宽度
	//jQ("#datepicker td").removeAttr("onclick");//移除JQ的原始动作
//	jQ("a.ui-state-default").css("padding","0.4em 0.8em");
//	jQ("a.ui-state-default").click(function(event){
//		if(jQ(this).hasClass("ui-diy-highlight")){
//			jQ(this).removeClass("ui-diy-highlight");//小日历多选功能
//		}else{
//			jQ(this).addClass("ui-diy-highlight");//小日历多选功能
//		}
//	});
}

function loadDefinedDateEvents(addLong){
	jQ.ajax({
		type:"POST",
		url: "manageClipAjax!loadDefinedDateEvents.action",
		data:{
			definedLong:addLong
		},
		success:function(data){
			var mobilenotice=eval(jQ("#var_hasmobile").val());
			organizeData(data,mobilenotice);
		}
	});
}

function loadTodayEvents(){
	jQ.ajax({
		type:"POST",
		url: "manageClipAjax!loadTodayEvents.action",
		success:function(data){
			var mobilenotice=eval(jQ(data).find("mobilenotice").text());
			organizeData(data,mobilenotice);
		}
	});
}

function organizeData(data,mobilenotice){
	var daylong=eval(jQ(data).find("day").text());
	if(jQ(data).find("EventForView").length==0){
		var html="";
		html="<div class='ms_box noeventday' dayattr='"+daylong+"'><div class='ms_tit'><span>"+formateTitleTime(daylong)+"</span><a></a></div><div class='ms_close'><a></a></div><div class='ms_con'><div class='me_list'><i>暂无</i></div></div></div>";
		jQ("#left_clip_list").append(html);
		jQ("#left_clip_list div.ms_box div.ms_tit").unbind("click").bind("click",leftCalendarEventsClick);
		jQ("div.ms_close a").unbind("click").bind("click",leftCalendarRemoveDate);
		return;
	}
	var html="<div class='ms_box ' dayattr='"+daylong+"'><div class='ms_tit'><span>"+formateTitleTime(daylong)+"</span><a></a></div><div class='ms_close'><a></a></div><div class='ms_con'>";
	
	jQ(data).find("EventForView").each(function(){
		var eventid=jQ(this).attr("id");
		var title=jQ(this).find("title").text();
		var eventtype=jQ(this).find("eventtype").text();
		var starttime=eval(jQ(this).find("starttime").text());
		var endtime=eval(jQ(this).find("endtime").text());
		var iswholeday=eval(jQ(this).find("iswholeday").text());
		var address=jQ(this).find("address").text();
		var clocktime=eval(jQ(this).find("clocktime").text());
		var deadlinetime=eval(jQ(this).find("deadlinetime").text());
		var isexpire=eval(jQ("isexpire",this).text());
		var isvip=eval(jQ(this).find("isvip").text());
		var timeattr=eval(jQ(this).attr("timeattr"));
		var processstatus=eval(jQ(this).find("processstatus").text());
		var reliedclip=eval(jQ(this).find("reliedclip").text());
		var publishname=jQ(this).find("publishname").text();
		
		var forwardname=jQ(this).find("forwardname").text();
		var puid=jQ(this).find("puid").text();
		var fuid=eval(jQ(this).find("fuid").text());
		var cliptype=eval(jQ(this).find("cliptype").text());
		
		var sub="<div class='me_list clipevent-"+eventid+"' cliptype='"+cliptype+"'>";
		sub+="<input type='hidden' class='eventid' value='"+eventid+"'>";
		sub+="<input type='hidden' class='clocktime' value='"+clocktime+"'>";
		sub+="<input type='hidden' class='isvip' value='"+isvip+"'>";
		sub+="<div class='me_item isvip'>";
		sub+="<span class='e_"+eventtype+"' title='"+getTypeName(eventtype)+"'></span>";
		sub+="<span class='title'>"+htmlData(title)+"</span>";
		if(isvip)
			sub+="<span class='c_import isvip' title='标记为不重要'></span>";
		else
			sub+="<span class='import isvip' title='标记为重要'></span>";
		sub+="</div><div class='me_item'>";
		if(reliedclip>0){
			sub+="<span>发起人：</span><span><a href='"+jQ("#ctxVal").val()+"/home/user.html?"+puid+"'>"+publishname+"</a></span>";
		}else
			sub+="<span>发起人：</span><span>"+publishname+"</span>";
		sub+="</div>";
		
		if(fuid>0){
			sub+="<div class='me_item'>";
			sub+="<span>转发人：</span><span><a href='"+jQ("#ctxVal").val()+"/home/user.html?"+fuid+"'>"+forwardname+"</a></span>";
			sub+="</div>";
		}
		sub+="<div class='me_item'>";
		if(iswholeday)
			sub+="<span class='time'><span style='width:auto;'>开始于</span><b>"+formateDetailTime(starttime)+"</b></span>";
		else
			sub+="<span class='time'><b>"+formateDetailTime(starttime)+"</b><i>-</i><b>"+formateDetailTime(endtime)+"</b></span>";
		if(processstatus==0){
			sub+="<b class='edt_ing'>进行中</b>";
		}else if(processstatus==1){
			sub+="<b class=\"edt_over\">已结束</b>";
		}else if(processstatus==2){
			sub+="<b class=\"edt_stop\">已停止</b>";
		}
		sub+="</div><div class='me_item'>";
		sub+="<span>截止：</span><span>";
		if(deadlinetime>0){
			sub+=formateDetailTime(deadlinetime);
			if(isexpire)
				sub+="<b class='expire'>已过期</b>";	
		}
		else
			sub+="<i>暂无</i>";
		sub+="</span>";
		
		sub+="</div><div class='me_item'>";
		sub+="<span>地址：</span><span class='adr'>"+htmlData(address)+"</span>";
		sub+="</div><div class='me_item me_clock show_clock'>";
		sub+="<span>提醒：</span>";
		if(clocktime>0){
			sub+="<span class='alarm clockval'>"+formateDetailTime(clocktime);
		}else{
			sub+="<span class='clockval'><i>暂无</i>";
		}
		sub+="</span>";
		sub+="</div><div class='me_item me_clock set_clock' style='display:none;'>";
		sub+="<span>提醒</span>";
		sub+="<input style='margin:0 5px;width:130px;' type='text' size='15' class='data'>";
		sub+="<div class='timebg hourbg'><a class='minus' onclick='hourminus(jQ(this).next());'></a>" +
				"<input maxlength='2' value='0' onblur='hourinput(this);' class='alert_hour'/>" +
				"<a class='plus' onclick='hourplus(jQ(this).prev());'></a></div>" +
				"<span class='tipt'>时</span>";
		sub+="<div class='timebg minbg'><a class='minus' onclick='minminus(jQ(this).next());'></a>" +
				"<input maxlength='2' value='0' onblur='mininput(this);' class='alert_min'/>" +
				"<a class='plus' onclick='minplus(jQ(this).prev());'></a></div>" +
				"<span class='tipt'>分</span>";
		if(mobilenotice)
			sub+="<input type='checkbox' class='hasmobilechoose' style='float:left;margin-top:8px;'/><img src='"+jQ("#ctxVal").val()+"/image/mobilemsg.png' width='16px' height='16px' style='float:left;margin-top:5px;' class='hasmobilechoose' alt='手机短信提醒' title='手机短信提醒'/>";
		sub+="<button>确定</button></div><div class='me_item set_clock_info' style='color:#ff0000;'></div><div class='me_item opt_item'>";
		if(reliedclip>0){
			if(processstatus==0)
				sub+="<a class='delicon f_leave' title='退出档期' style='margin-right:13px;'></a>";
			else
				sub+="<a class='delicon f_leave' title='删除档期' style='margin-right:13px;'></a>";
		}else{
			sub+="<a class='delicon f_del' title='取消档期' style='margin-right:13px;'></a>";
		}
		sub+="<a class='f_info' title='档期详情'></a>";
		if(clocktime>0){
			sub+="<a class='alarmicon f_c_alarm' title='取消提醒' ></a>";
		}else{
			sub+="<a class='alarmicon f_alarm' title='设置提醒' ></a>";
		}
		sub+="</div></div>";
		
		html+=sub;
	});
	html+="</div></div>";
	jQ("#left_clip_list").append(html);
	jQ("#left_clip_list div.ms_box div.ms_tit").unbind("click").bind("click",leftCalendarEventsClick);
	jQ("div.ms_con div.me_list div.isvip span.isvip").unbind("click").bind("click",leftCalendarSetImport);
	jQ("div.ms_con div.me_list div.opt_item a.delicon").unbind("click").bind("click",leftCalendarDeleteEvent);
	jQ("div.ms_con div.me_list div.opt_item a.f_info").unbind("click").bind("click",function(event){
		var eventid=jQ(event.currentTarget).parent().prevAll("input.eventid").val();
		window.location.href=jQ("#ctxVal").val()+"/myclip/clip_detail.html?eventid="+eventid;
	});
	jQ("div.ms_con div.me_list div.opt_item a.alarmicon").unbind("click").bind("click",function(event){
		if(jQ(this).hasClass("f_c_alarm")){
			leftCalendarCancelClock(event);
		}else if(jQ(this).hasClass("f_alarm")){
			leftCalendarAddClockAtLeft(event);
		}
	});
	
	jQ("div.ms_close a").unbind("click").bind("click",leftCalendarRemoveDate);
	
}

function leftCalendarAddClockAtLeft(event){
	var eventid=jQ(event.currentTarget).parent().prevAll("input.eventid").val();
	var showclock=jQ(event.currentTarget).parent().prevAll("div.show_clock");
	var setclock=jQ(event.currentTarget).parent().prevAll("div.set_clock");
//	var iconObj=jQ(event.currentTarget);
	if(showclock.css("display")=="none"){
		jQ(event.currentTarget).parent().prevAll("div.set_clock_info").empty().hide();
		setclock.hide();
		showclock.show();
		return;
	}
	showclock.hide();
	setclock.show();
	setclock.find("input:checkbox").attr("checked","true");
	setclock.find("input.data").val("");
	setclock.find("input.alert_hour").val(0);
	setclock.find("input.alert_min").val(0);
	setclock.find("input.data").datepicker({
		yearRange : '1950:2020',
		dateFormat:'yy-mm-dd',
		changeMonth:true,
		changeYear:true,
		beforeShow: function(i,e){  
		var z = jQuery(i).closest(".ui-dialog").css("z-index") + 4;  
		e.dpDiv.css('z-index', z);  
	}});
	
	
	setclock.find("button").unbind("click").bind("click",function(){
		
		var isChecked=eval(jQ(this).prevAll("input:checkbox").attr("checked"));
		var errzone=jQ(this).parent().nextAll("div.set_clock_info");
			var alertdateval=jQ(this).prevAll("input:text").val();
			if(alertdateval==null||alertdateval.length<=0){
				errzone.empty();
				errzone.append("请选择提醒的时间。");
				errzone.show();
				return;
			}else{
				errzone.empty();
			}
			
			var alertdate=jQ(this).prevAll("input:text").datepicker( "getDate" );
			var alerthour=eval(jQ(this).prevAll("div.hourbg").find("input.alert_hour").val());
			var alertmin=eval(jQ(this).prevAll("div.minbg").find("input.alert_min").val());
			alertdate.setHours(alerthour);
			alertdate.setMinutes(alertmin);
			var alertlong=alertdate.getTime();
			var nowdate=new Date();
			if(alertlong<nowdate){
				errzone.empty();
				errzone.append("提醒的时间应该是将来的时间。");
				errzone.show();
				return;
			}else{
				errzone.empty();
			}
			var mobilenotice=0;
			var checked=eval(jQ(this).prevAll("input:checkbox").attr("checked"));
			if(eval(jQ("#var_hasmobile"))&&checked){
				mobilenotice=1;
			}
			var btnObj=jQ(this);
			jQ.ajax({
				type: "POST",
				url:"eventAjax!addEventClock.action",
				data:{
					eventid:eventid,
					alerttime:alertlong,
					mobilenotice:mobilenotice
				},
			success:function(data){
				if(data!=null){
					var dataObj=eval("("+data+")");//转换为json对象
					if(dataObj['result']){
						
						setclock.hide();
						showclock.show();
						btnObj.unbind("click");
						jQ("div.clipevent-"+eventid+" input.clocktime").val(alertlong);
						var ss=jQ("div.clipevent-"+eventid+" div.show_clock span.clockval");
						ss.addClass("alarm").empty().append(formateDetailTime(alertlong));
						var ss2=jQ("div.clipevent-"+eventid+" div.opt_item a.alarmicon");
						ss2.removeClass("f_alarm").addClass("f_c_alarm").attr("title","取消提醒");
						ss2.unbind("click").bind("click",leftCalendarCancelClock);
						loadRemindMainpartRecords();
					}else{
					}
				}
			}
			});
	});
}

function leftCalendarCancelClock(event){
	var eventid=jQ(event.currentTarget).parent().prevAll("input.eventid").val();
	var setclock=jQ(event.currentTarget).parent().prevAll("div.set_clock");
	var showclock=jQ(event.currentTarget).parent().prevAll("div.show_clock");
	var iconObj=jQ(event.currentTarget);
	jQ.ajax({
		type: "POST",
		url:"eventAjax!cancelClock.action",
		data:{
			eventid:eventid
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					setclock.hide();
					showclock.show();
					jQ("div.clipevent-"+eventid+" input.clocktime").val(0);
					var ss=jQ("div.clipevent-"+eventid+" div.show_clock span.clockval");
					ss.removeClass("alarm").empty().append("<i>暂无</i>");
					var ss2=jQ("div.clipevent-"+eventid+" div.opt_item a.alarmicon");
					ss2.removeClass("f_c_alarm").addClass("f_alarm").attr("title","设置提醒");
					ss2.unbind("click").bind("click",leftCalendarAddClockAtLeft);
					serializeClipEventLeftToCenter(eventid);
				}else{
					
				}
			}
		}
	});
}

function leftCalendarRemoveDate(event){
	var curObj=jQ(event.currentTarget);
	curObj.parent().parent().fadeOut("normal",function(){
		   jQ(this).remove();
	 });
}

function leftCalendarDeleteEvent(event){
	var curObj=jQ(event.currentTarget);
	var info="";
	var title="";
	if(curObj.hasClass("f_leave")){
		var cliptypenode=curObj.parent().parent();
		var cliptype=eval(cliptypenode.attr("cliptype"));
		if(cliptype==3){
			info="您确定退出档期么？<p>分享档期将不被保存在回收站内";
		}else
			info="您确定退出档期么？";
		title="退出档期";
	}else if(curObj.hasClass("f_del")){
		info="您确定取消档期么？";
		title="取消档期";
	}
	var eventid=curObj.parent().prevAll("input.eventid").val();
	jQ("#viewopt_eventid").val(eventid);
	var opt=jQ("#viewopt");
	opt.bind("deleteEvent",deleteEventAtLeftCalendar);
	opt.data("function","deleteEvent")
	jQ("#viewopt_p").empty().append(info);
	jQ("#viewopt").dialog( "option", "title", title);
	jQ("#viewopt").dialog("open");
}

function leftCalendarEventsClick(event){
	var curObj=jQ(event.currentTarget);
	if(curObj.find("a").hasClass("expend")){
		curObj.find("a").removeClass("expend");
		curObj.nextAll("div.ms_con").slideUp();
	}else{
		curObj.find("a").addClass("expend");
		curObj.nextAll("div.ms_con").slideDown();
	}
}

function leftCalendarSetImport(event){
	var curObj=jQ(event.currentTarget);
	var eventid=eval(curObj.parent().prevAll("input.eventid").val());
	var ss=jQ("div.clipevent-"+eventid+" div.isvip span.isvip");
	if(curObj.hasClass("c_import")){
		
		ss.removeClass("c_import").addClass("import");
		ss.attr("title","标记为重要");
		jQ("div.clipevent-"+eventid+" input.isvip").val(0);
		setImport(false,eventid);
	}else if(curObj.hasClass("import")){
		
		ss.removeClass("import").addClass("c_import");
		ss.attr("title","标记为不重要");
		jQ("div.clipevent-"+eventid+" input.isvip").val(1);
		setImport(true,eventid);
	}
	serializeClipEventLeftToCenter(eventid);
	
}

function serializeClipEventLeftToCenter(eventid){
	var leftObjs=jQ("div.clipevent-"+eventid);
	if(leftObjs.length==0){
		jQ("#clipevent-"+eventid).remove();
		reloadCacheAndClockCount();
		return;
	}
	var isvip=eval(leftObjs.find("input.isvip").val());
	var trObjs=jQ("#clipevent-"+eventid);
	trObjs.find("input.isvip").val(isvip);
	var mainvipobj=jQ("div.isvip-"+eventid+" span.isvip");
	if(isvip){
		if(!mainvipobj.hasClass("c_import")){
			mainvipobj.removeClass("import").addClass("c_import").attr("title","重要档期");
		}
	}else{
		if(!mainvipobj.hasClass("import")){
			mainvipobj.removeClass("c_import").addClass("import").attr("title","不重要档期");
		}
	}
	var clocktime=eval(leftObjs.find("input.clocktime").val());
	if(clocktime==0){
		jQ("#clipevent-"+eventid).remove();
		reloadCacheAndClockCount();
		return;
	}
}

function serializeClipEventCenterToLeft(eventid){
	var trObj=jQ("#clipevent-"+eventid);
	var isvip=eval(jQ(trObj).find("input.isvip").val());
	var leftObjs=jQ("div.clipevent-"+eventid);
	leftObjs.find("input.isvip").val(isvip);
	if(isvip)
		leftObjs.find("div span.isvip").removeClass("import").addClass("c_import").attr("title","标记为不重要");
	else
		leftObjs.find("div span.isvip").removeClass("c_import").addClass("import").attr("title","标记为重要");
}

function deleteEventAtLeftCalendar(){
	var eventid=jQ("#viewopt_eventid").val(); 
	jQ.ajax({
		type: "POST",
		url:"eventAjax!deleteEvent.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['result']){
					jQ("#viewopt").dialog("close");
					jQ("div.clipevent-"+eventid).remove();
					noeventInLeftCalendar();
//					noeventInLeft();
					serializeClipEventLeftToCenter(eventid);
				}else{
					jQ("#viewopt_p").empty().append(dataObj['msg']);
					jQ("#viewopt").dialog("close");
				}
			}
		}
	});
}

function noeventInLeftCalendar(){
	var tmp="";
	jQ("#left_clip_list div.ms_box").each(function(){
		if(jQ(this).find("div.ms_con div").length==0){
			tmp="<div class='me_list'><i>暂无</i></div>";
			jQ(this).find("div.ms_con").empty().append(tmp);
		}
	});
}

function setImport(isImport,eventid){
	jQ.ajax({
		type: "POST",
		url:"eventAjax!setEventImport.action",
		data:{
			isImport:Number(isImport),
			eventid:eval(eventid)
		},
		success:function(data){
		}
	});
}

function selectAllRecords(obj){
	if(jQ(obj).hasClass("checkallcheck")){
		jQ("input.cbx").attr("checked",false);
		jQ("div.upblock a").removeClass("checkallcheck");
		jQ("div.dwblock a").removeClass("checkallcheck");
	}else{
		jQ("input.cbx").attr("checked",true);
		jQ("div.upblock a").addClass("checkallcheck");
		jQ("div.dwblock a").addClass("checkallcheck");
	}
}
function selected2CancelClock(){
	var info="";
	var title="";
	info="您确定取消这些档期的提醒么？";
	title="取消提醒";
	var opt=jQ("#viewopt");
	opt.bind("cancelClocksEvent",cancelClocks);
	opt.data("function","cancelClocksEvent")
	jQ("#viewopt_p").empty().append(info);
	jQ("#viewopt").dialog( "option", "title", title);
	jQ("#viewopt").dialog("open");
	
}
function cancelClocks(){
	if(jQ("input.per:checked").length==0){
		alert("您还未选择需要关闭提醒的档期。");
		return;
	}
	jQ("input.per:checked").each(function(){
		var eventid=eval(jQ(this).prev("input:hidden").val());
		jQ.ajax({
			type: "POST",
			url:"eventAjax!cancelClock.action",
			data:{
				eventid:eventid
			},
			success:function(data){
				if(data!=null){
					var dataObj=eval("("+data+")");//转换为json对象
					if(dataObj['result']){
						jQ("#clipevent-"+eventid).remove();
					}else{
						
					}
				}
			}
		});
	});
	jQ("#viewopt").dialog("close");
	loadRemindMainpartRecords();
}
function reloadCacheAndClockCount(){
	jQ.ajax({
		type: "POST",
		url:"manageClipAjax!loadCacheAndClockCount.action",
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(eval(dataObj.result)){
					var clocktotalcount=eval(dataObj.clocktotalcount);
					jQ("#clipevent_clocknum").empty().append("("+clocktotalcount+")");
					var cachetotalcount=eval(dataObj.cachetotalcount);
					jQ("#clipevent_cachenum").empty().append("("+cachetotalcount+")");
				}
			}
		}
	});
}

function selected2Important(){
	jQ("input.per:checked").each(function(){
		var eventid=eval(jQ(this).prev("input:hidden").val());
		var vipObj=jQ("div.isvip-"+eventid+" span.isvip");
		if(vipObj.hasClass("c_import")){
			return;
		}else{
			jQ("#clipevent-"+eventid).find("input.isvip").val(1);
			serializeClipEventCenterToLeft(eventid);
			vipObj.removeClass("import").addClass("c_import").attr("title","重要档期");
			setImport(true,eventid);
		}
	});
}

function selected2Unimportant(){
	jQ("input.per:checked").each(function(){
		var eventid=eval(jQ(this).prev("input:hidden").val());
		var vipObj=jQ("div.isvip-"+eventid+" span.isvip");
		if(vipObj.hasClass("import")){
			return;
		}else{
			jQ("#clipevent-"+eventid).find("input.isvip").val(0);
			serializeClipEventCenterToLeft(eventid);
			vipObj.removeClass("c_import").addClass("import").attr("title","不重要档期");
			setImport(false,eventid);
		}
	});
}

function filterEvent(obj,typename){
	var flag=eval(jQ(obj).attr("checked"));
	if(typename=='other'){
		var eventobjs=jQ("div.eventtype-other").parent().parent();
		jQ("div.filter-other input:checkbox").attr("checked",flag);
		if(flag){
			eventobjs.show();
		}else{
			eventobjs.hide();
		}
	}else if(typename=='work'){
		var eventobjs=jQ("div.eventtype-work").parent().parent();
		jQ("div.filter-work input:checkbox").attr("checked",flag);
		if(flag){
			eventobjs.show();
		}else{
			eventobjs.hide();
		}
	}else if(typename=='socal'){
		var eventobjs=jQ("div.eventtype-socal").parent().parent();
		jQ("div.filter-socal input:checkbox").attr("checked",flag);
		if(flag){
			eventobjs.show();
		}else{
			eventobjs.hide();
		}
	}else if(typename=='sect'){
		var eventobjs=jQ("div.eventtype-sect").parent().parent();
		jQ("div.filter-sect input:checkbox").attr("checked",flag);
		if(flag){
			eventobjs.show();
		}else{
			eventobjs.hide();
		}
	}else if(typename=='import'){
		jQ("div.filter-import input:checkbox").attr("checked",flag);
		jQ("td.isvip div span.import").each(function(){
			if(flag){
				jQ(this).parent().parent().parent().show();
			}else{
				jQ(this).parent().parent().parent().hide();
			}
			
		});
	}else if(typename=='c_import'){
		jQ("div.filter-c_import input:checkbox").attr("checked",flag);
		jQ("td.isvip div span.c_import").each(function(){
			if(flag){
				jQ(this).parent().parent().parent().show();
			}else{
				jQ(this).parent().parent().parent().hide();
			}
			
		});
	}
}

function formateDetailTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy-MM-dd HH:mm");
}

function formateTitleTime(daytime){
	var temp=new Date();
	temp.setTime(eval(daytime));
	return temp.pattern("yyyy年MM月dd日");
}

function getTypeName(eng){
	if(eng=='other'){
		return "其他";
	}else if(eng=='work'){
		return "工作";
	}else if(eng=='socal'){
		return "社交";
	}else if(eng=='sect'){
		return "私人";
	}
}